package com.gz.droolsrule.service;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.github.pagehelper.util.StringUtil;
import com.gz.droolsrule.dao.BaseRuleInfoMapper;
import com.gz.droolsrule.pojo.BaseRuleInfo;
import com.gz.droolsrule.pojo.BaseRulePropertyInfo;
import com.gz.droolsrule.pojo.BaseRulePropertyRelInfo;
import com.gz.droolsrule.pojo.BaseRuleSceneInfo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * ClassName: RuleInfoService <br/>
 * Description: <br/>
 * date: 2019/5/31 15:59<br/>
 *
 * @author gz<br />
 * @since JDK 1.8
 */
@Service
public class RuleInfoService {
    @Autowired
    private  BaseRuleInfoMapper baseRuleInfoMapper;

    /**
     * 方法说明: 获取规则集合信息
     *
     * @param baseRuleInfo 参数
     * @param page         分页参数
     */
    public PageInfo<BaseRuleInfo> findBaseRuleInfoPage(BaseRuleInfo baseRuleInfo, PageInfo page) {

        PageHelper.startPage(page.getPageNum(),page.getPageSize());
        List<BaseRuleInfo> list = this.baseRuleInfoMapper.findBaseRuleInfoList(baseRuleInfo);
        return new PageInfo<>(list);
    }

    /**
     * 方法说明: 查询规则属性信息
     *
     * @param baseRulePropertyInfo 参数
     */
    public List<BaseRulePropertyInfo> findBaseRulePropertyInfoList(BaseRulePropertyInfo baseRulePropertyInfo) {
        return this.baseRuleInfoMapper.findBaseRulePropertyInfoList(baseRulePropertyInfo);
    }

    /**
     * 方法说明: 根据规则获取已经配置的属性信息
     *
     * @param ruleId 参数
     */
    public List<BaseRulePropertyRelInfo> findRulePropertyListByRuleId(final Long ruleId) {
        return this.baseRuleInfoMapper.findRulePropertyListByRuleId(ruleId);
    }

    /**
     * 方法说明: 根据场景获取对应的规则信息
     *
     * @param baseRuleSceneInfo 参数
     */
    public List<BaseRuleInfo> findBaseRuleListByScene(BaseRuleSceneInfo baseRuleSceneInfo) {
        if (null == baseRuleSceneInfo || (null == baseRuleSceneInfo.getSceneId() &&
                StringUtil.isEmpty(baseRuleSceneInfo.getSceneIdentify()))) {
            return null;
        }
        return this.baseRuleInfoMapper.findBaseRuleListByScene(baseRuleSceneInfo);
    }
}
